package com.polaris.live.adapter

import android.graphics.Color
import com.blankj.utilcode.util.ColorUtils
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterSetLanguageBinding
import com.polaris.live.resp.back_resp.LanguageResp

/**
 * 选择语言的adapter
 *
 * @author Created by 半仙 on 2023/9/4/004 12:52
 */
class SetLanguageAdapter :
    BaseBindingAdapter<AdapterSetLanguageBinding, LanguageResp>() {

    private var selectPosition = -1

    override fun convert(holder: VBViewHolder<AdapterSetLanguageBinding>, item: LanguageResp) {
        holder.vb.apply {
            val position = holder.absoluteAdapterPosition
            languageText.text = item.localName
            if (position == selectPosition) {
                llLanguageBack.setBackgroundResource(R.drawable.gradient_fa3a9e_fe1849_fc772a)
                languageText.setTextColor(ColorUtils.getColor(R.color.commonButtomTextColor))
            } else {
                llLanguageBack.setBackgroundResource(R.drawable.r26_back_f1f1f1)
                languageText.setTextColor(Color.parseColor("#57575C"))
            }
        }
    }

    fun setSelect(position: Int) {
        selectPosition = position
        notifyDataSetChanged()
    }

    fun clearSelected() {
        if (selectPosition == -1) {
            return
        }
        val index = selectPosition
        selectPosition = -1
        notifyItemChanged(index)
    }

}